<%@page import="com.tt.control.UserManager"%>
<%@page import="java.sql.Timestamp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ page import="com.tt.control.*, com.tt.shpping.*" %>
<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%!
String check = "";
%>
<%
String action = request.getParameter("action");
if(action!=null &&action.equals("register")) {
	out.print(1);
	User u = new User();
	u.setUsername(request.getParameter("name"));
	u.setPassword(request.getParameter("pswd1"));
	u.setPhone(request.getParameter("tele"));
	u.setAddr(request.getParameter("address"));
	if(UserManager.checkName(request.getParameter("name"))){
		UserManager.save(u);
		check = "注册成功";
	}else {
		check = "用户名已被使用";
	}
	
}
%>
<script type="text/javascript">
	var num = 0;
	window.onload = function() {
		<%=check%>="";
		check();
		var form = document.getElementById("form1");
		form.onsubmit = function() {
			if(num == 5) {
				return true;
			}else {
				return false;
			}
			
		};
		//var button = document.getElementById("form1");
	}
	function check() {
		checkUsername();
		checkPassword();
		checkPassword2();
		checkPhone();
		checkAddress();
	}
		function checkUsername() {
			var username = document.getElementById("name");
			var sname = document.getElementById("sname");
			username.onblur = function() {
				if(username.value=="") {
					sname.innerHTML="用户名不能为空";
					sname.style.color="red";
				}else if(username.value.length<6) {
					sname.innerHTML="用户名的长度不能小于6";
						sname.style.color="red";
				}else {
					sname.innerHTML="";
					num+=1;
				}
			}
		}
		function checkPassword() {
			
			var pswd = document.getElementById("pswd1");
			var spswd = document.getElementById("spswd1");
			pswd.onblur = function() {
				if(pswd.value=="") {
					alert(pswd.value);
					spswd.innerHTML="密码不能为空";
					spswd.style.color="red";
				}else if( pswd.value.length<6) {
					spswd.innerHTML="密码的长度不能小于6";
					spswd.style.color="red";
				}else {
					spswd.innerHTML="";
					num+=1;
				}
			}
		}
		function checkPassword2() {
			
			var pswd1 = document.getElementById("pswd1");
			var pswd2 = document.getElementById("pswd2");
			var spswd2 = document.getElementById("spswd2");
			pswd2.onblur = function() {
				if( pswd2.value!=pswd1.value) {
					spswd2.innerHTML="两次输入的密码不一致";
					spswd2.style.color="red";
				}else {
					spswd2.innerHTML="";
					num+=1;
				}
			}
		}
		function checkPhone() {
			var tele = document.getElementById("tele");
			var stele = document.getElementById("stele");
			tele.onblur = function() {
				if( tele.value=="") {
					stele.innerHTML="联系方式不能为空";
					stele.style.color="red";
				}else {
					stele.innerHTML="";
					num+=1;
				}
			}
		}
		function checkAddress() {
			var address= document.getElementById("address");
			var saddress = document.getElementById("saddress");
			address.onblur = function() {
				if( address.value=="") {
					saddress.innerHTML="地址不可以为空";
					saddress.style.color="red";
				}else {
					saddress.innerHTML="";
					num+=1;
				}
			}
		}
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户注册</title>
<link href="../css/register.css" rel="stylesheet"/>

</head>
<body>
<form action="register.jsp" method="post" id="form1" name="form1">
<input type ="hidden" name="action" value="register">
<table  border="1" width="600px" height="300px"  id="table">
	<tr > 
		<td colspan="3" textalign="center" id ="re" >用户注册</td>
	</tr>
	
	<tr>
		<td style="width:100px">用户名：</td>
		<td><input type="text" name="name" id="name" style="width:250px"  />
		<span id="sname" style="width:200px">用户名的不小于6位</span></td>
	</tr>
	 
	
	<tr>
		<td style="width:100px">密码：</td>
		<td><input type="password" name="pswd1" id="pswd1" style="width:250px" />
		<span id="spswd1" style="width:200px">密码不小于6位</span></td>
	</tr>
	<tr>
		<td style="width:100px">确认密码：</td>
		<td><input type="password" name="pswd2" id="pswd2" style="width:250px" />
		<span id="spswd2" style="width:200px"></span></td>
	</tr>
	
	<tr>
		<td style="width:100px">电话：</td>
		<td><input type="text" name="tele" id="tele" style="width:250px" />
		<span id="stele" style="width:200px">电话不能为空</span></td>
	</tr>
	<tr >
		<td style="width:100px">送货地址：</td>
		<td rowspan="3" ><textarea id="address" name="address" clos="8" rows="5" style="width:200px" ></textarea>
			<span id="saddress" style="width:250px">地址不能为空</span></td>
		
	</tr>
	<tr></tr>
	<tr></tr>
	<tr></tr>
	<tr></tr>
	<tr>
		<td></td>
		<td colspan="2"><input type="submit" value="提交"/>
			<input type="reset" value="重置"/>
			<span id="check" style="width:250px, font-color:red"><%=check%></span></td>
			<td></td>
	</tr>

</table>



</form>

</body>
</html>